/*
 * EditACLInterface.java
 *
 * Created on May 29, 2006, 6:23 PM
 *
 * @author  Francois Daniels
 */
import java.awt.*;
import za.gateway.preferences.Settings;

public class EditACLInterface extends javax.swing.JDialog {
    
    /** Creates new form EditACLInterface */
    public EditACLInterface (java.awt.Frame parent, boolean modal) {
        super (parent, modal);
        initComponents ();
        updateComponents ();
    }
    
    private void updateComponents () {
        
        if (Settings.isWindows) {
            try {
                javax.swing.UIManager.setLookAndFeel (
                        "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                javax.swing.SwingUtilities.updateComponentTreeUI (this);
                pack ();
            } catch (Exception e) { }
        }
    }
    
    public void setVisible (boolean b) {
        centerOnParentAndShow ();
        super.setVisible (b);
    }
    
    private void centerOnParentAndShow () {
        pack ();
        Container parent = getParent ();
        if (parent == null) return;
        
        Dimension dparent = parent.getSize ();
        Dimension window = getSize ();
        int xCoord, yCoord;
        try {
            xCoord = parent.getLocationOnScreen ().x + (dparent.width/2 -
                    window.width/2);
            yCoord = parent.getLocationOnScreen ().y + (dparent.height/2 -
                    window.height/2);
        } catch (IllegalComponentStateException e) {return;}
        
        //Ensure that no part of the window will be off-screen
        Dimension screen = Toolkit.getDefaultToolkit ().getScreenSize ();
        int xOffScreenExcess = xCoord + window.width - screen.width;
        if ( xOffScreenExcess > 0 ) {
            xCoord = xCoord - xOffScreenExcess;
        }
        if (xCoord < 0 ) {
            xCoord = 0;
        }
        int yOffScreenExcess = yCoord + window.height - screen.height;
        if ( yOffScreenExcess > 0 ) {
            yCoord = yCoord - yOffScreenExcess;
        }
        if (yCoord < 0) {
            yCoord = 0;
        }
        
        setLocation ( xCoord, yCoord );
    }
    
    // <editor-fold defaultstate="collapsed" desc=" Code generated by Netbeans for the GUI Components  ">
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Edit Access Control Element");
        setResizable(false);
        jTextField1.setEditable(false);
        jTextField1.setText("Nurses");

        jTextField2.setEditable(false);
        jTextField2.setText("Medical Dispensary");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Block", "Allow", "Allow during the day", "Block during the day" }));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Group Name");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Restriction");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Phone Number");

        jButton1.setText("OK");

        jButton2.setText("Cancel");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 112, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                            .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 188, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                            .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 356, Short.MAX_VALUE)
                        .add(jButton2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
    public static void main (String args[]) {
        java.awt.EventQueue.invokeLater (new Runnable () {
            public void run () {
                new EditACLInterface (new javax.swing.JFrame (), 
                        true).setVisible (true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
    
}
